<%--
  Created by IntelliJ IDEA.
  User: HKemmm
  Date: 2022/3/10
  Time: 17:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head lang="en">
    <meta charset="utf-8"/>
    <title>个人信息</title>
    <link rel="stylesheet" type="text/css" href="/static/css/public.css"/>
    <link rel="stylesheet" type="text/css" href="/static/css/mygrxx.css"/>

    <style>
        #btn_ok {
            display: block;
            width: 60px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            margin: 20px 0 0 30%;
            background: #A10000;
            color: #fff;
            cursor: pointer;
        }
    </style>
</head>
<body>
<!------------------------------head------------------------------>
<div class="head ding">
    <div class="wrapper clearfix">
        <div class="clearfix" id="top">
            <h1 class="fl"><a href="/page/index.jsp"><img src="/static/moban/img/logo/logo.png"/></a></h1>
            <div class="fr clearfix" id="top1">
                <p class="fl">
                    <a href="#" id="login">登录</a>
                    <a href="#" id="reg">注册</a>
                </p>
                <form action="#" method="get" class="fl">
                    <input type="text" placeholder="搜索"/>
                    <input type="hidden" id="userId" value="${sessionScope.User.id}">
                    <input type="button"/>
                </form>
                <div class="btn fl clearfix">
                    <a href="mygxin.html"><img src="/static/img/grzx.png"/></a>
                    <a href="#" class="er1"><img src="/static/img/ewm.png"/></a>
                    <a href="cart.html"><img src="/static/img/gwc.png"/></a>
                    <p><a href="#"><img src="/static/img/smewm.png"/></a></p>
                </div>
            </div>
        </div>
    </div>
</div>
<!------------------------------idea------------------------------>
<div class="address mt">
    <div class="wrapper clearfix">
        <a href="index.html" class="fl">首页</a>
        <span>/</span>
        <a href="mygxin.html" class="on">个人信息</a>
    </div>
</div>

<!------------------------------Bott------------------------------>
<div class="Bott">
    <div class="wrapper clearfix">
        <div class="zuo fl">
            <h3>
                <a><img class="zuo-img" src="/myimg/${sessionScope.User.photo}"/></a>
                <p class="clearfix">
                    <span class="fl">[${sessionScope.User.name}]</span>
                    <a href="/shop/exit"><span class="fr">[退出登录]</span></a>
                </p>
            </h3>
            <div>
                <h4>我的交易</h4>
                <ul>
                    <li><a href="/shop/car?id=${sessionScope.User.id}">我的购物车</a></li>
                    <li><a href="/jump/mysorder">我的订单</a></li>
                    <li><a href="/jump/myprod">评价晒单</a></li>
                </ul>
                <h4>个人中心</h4>
                <ul>
                    <li><a href="/shop/centre">我的中心</a></li>
                    <li><a href="/address/addressInfo?uid=${sessionScope.User.id}">地址管理</a></li>
                </ul>
                <h4>账户管理</h4>
                <ul>
                    <li><a href="/jump/mygrxx">个人信息</a></li>
                    <li class="on"><a href="/jump/remina">修改密码</a></li>
                </ul>
            </div>
        </div>
        <div class="you fl">
            <h2>修改密码</h2>
            <form action="#" method="get" class="remima">
                <p><span>选择验证身份方式：</span><input type="checkbox"/>密码验证 <input type="checkbox"/>邮箱验证 </p>
                <p><span>原密码：</span>
                    <input id="old_password" type="text"/>
                    <input id="password" value="${sessionScope.User.password}" type="hidden">
                </p>
                <p class="op caution1">输入原密码</p>
                <p><span>新密码：</span><input id="new_password1" type="text"/></p>
                <p class="op caution2">6-16 个字符，需使用字母、数字或符号组合，不能使用纯数字、纯字母、纯符号</p>
                <p><span>重复新密码：</span><input id="new_password2" type="text"/></p>
                <p class="op caution3">请再次输入密码</p>
                <p><span>验证码：</span>
                    <input id="code" type="text"/><input type="hidden" id="code1">
                    <img id="img_check" alt=""/>
                </p>
                <p class="op caution4">按右图输入验证码，不区分大小写</p>
                <input id="btn_ok" onclick="alterPassword()" type="button" value="提交"/>
            </form>
        </div>
    </div>
</div>

<!--返回顶部-->
<div class="gotop">
    <a href="cart.html">
        <dl>
            <dt><img src="/static/img/gt1.png"/></dt>
            <dd>去购<br/>物车</dd>
        </dl>
    </a>
    <a href="#" class="dh">
        <dl>
            <dt><img src="/static/img/gt2.png"/></dt>
            <dd>联系<br/>客服</dd>
        </dl>
    </a>
    <a href="mygxin.html">
        <dl>
            <dt><img src="/static/img/gt3.png"/></dt>
            <dd>个人<br/>中心</dd>
        </dl>
    </a>
    <a href="#" class="toptop" style="display: none">
        <dl>
            <dt><img src="/static/img/gt4.png"/></dt>
            <dd>返回<br/>顶部</dd>
        </dl>
    </a>
    <p>400-800-8200</p>
</div>
<!--footer-->
<div class="footer">
    <div class="top">
        <div class="wrapper">
            <div class="clearfix">
                <a href="#2" class="fl"><img src="/static/img/foot1.png"/></a>
                <span class="fl">7天无理由退货</span>
            </div>
            <div class="clearfix">
                <a href="#2" class="fl"><img src="/static/img/foot2.png"/></a>
                <span class="fl">15天免费换货</span>
            </div>
            <div class="clearfix">
                <a href="#2" class="fl"><img src="/static/img/foot3.png"/></a>
                <span class="fl">满599包邮</span>
            </div>
            <div class="clearfix">
                <a href="#2" class="fl"><img src="/static/img/foot4.png"/></a>
                <span class="fl">手机特色服务</span>
            </div>
        </div>
    </div>
    <p class="dibu">最家家居&copy;2013-2017公司版权所有 京ICP备080100-44备0000111000号<br/>
        违法和不良信息举报电话：400-800-8200，本网站所列数据，除特殊说明，所有数据均出自我司实验室测试</p>
</div>
<script src="/static/js/jquery-1.12.4.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/js/public.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/js/user.js" type="text/javascript" charset="utf-8"></script>

<script>
    $(function () {
        /*这个可以防止浏览器后退时候图片不刷新*/
        $("#img_check").prop("src", "/IdentifyingCodeServlet?" + new Date().getTime());
        setTimeout(function () {
            $.get("/code", function (data) {
                cod1 = data;
                $("#code1").val(data);

            });
        }, 500);

        /*点击生成新的验证码*/
        $("#img_check").click(function () {
            $(this).prop("src", "/IdentifyingCodeServlet?" + new Date().getTime());
            setTimeout(function () {
                $.get("/code", function (data) {
                    cod1 = data;
                    $("#code1").val(data);

                });
            }, 500);
        });
    })


    function alterPassword() {
        var password = $("#password").val();
        var oldPassword = $("#old_password").val();
        var newPassword1 = $("#new_password1").val();
        var newPassword2 = $("#new_password2").val();
        var id = $("#userId").val();
        var code = $("#code").val();
        var code1 = $("#code1").val();


        if (oldPassword != password) {
            alert("原密码错误！！！");

            return false;
        }

        if (newPassword1 != newPassword2) {
            alert("两次密码不一致!!!");

            return false;
        }

        if (oldPassword == "" || newPassword1 == "" || newPassword2 == "") {
            alert("请完善信息！！");

            return false;
        }

        if (code != code1) {
            $("#img_check").prop("src", "/IdentifyingCodeServlet?" + new Date().getTime());
            setTimeout(function () {
                $.get("/code", function (data) {
                    cod1 = data;
                    $("#code1").val(data);

                });
            }, 500);

            alert("验证码错误!!!");

            return false;
        }

        $.ajax({
            url: "/shop/update",
            data: {
                id: id,
                password: newPassword1
            },
            type: "POST",
            success: function (reqponse) {
                if (reqponse == "ok") {
                    alert("修改成功！！");
                    window.location = "/page/login.jsp";
                } else {
                    alert("修改失败！！");
                }
            },
            error: function (err) {
                console.log(err);
            }
        })

    }
</script>
</body>
</html>

